package com.czk.netty.netty.http;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * @Author:ChenZhangKun
 * @Date: 2021/1/14 21:49
 */
public class HttpServer {
    public static void main(String[] args) {
        EventLoopGroup bossGroup = null;
        EventLoopGroup workGroup = null;
        try {
            bossGroup = new NioEventLoopGroup(1);
            workGroup = new NioEventLoopGroup();
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap
                    .group(bossGroup, workGroup)
                    .channel(NioServerSocketChannel.class)
                    // 此时是在bossGroup的handler
                    //.handler()
                    // 对应的是workGroup的handler
                    .childHandler(new HttpServerInitializer());
            // 绑定端口
            ChannelFuture sync = bootstrap.bind(7001).sync();
            sync.channel().closeFuture().sync();
        } catch (Exception ex) {

        } finally {

        }
    }
}
